package main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import com.zj.MyActionInterceptor;

import cn.hn.java.summer.Config;
import cn.hn.java.summer.db.mapper.rule.IBeanMapperRule;
import cn.hn.java.summer.db.mapper.rule.UnderlinedBeanMapperRule;
import cn.hn.java.summer.web.WebApp;

@EnableScheduling
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
@SpringBootApplication(scanBasePackages={"com.zj"})
@Configuration()
@EnableTransactionManagement
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class App extends WebApp
{
    public static void main( String[] args )
    {
        Config.dbBeanScanFilter=".*sample.*db";
        Config.isIsSupportSetRestfulViewName =true;
    	SpringApplication.run(App.class);
    }

    @Bean
    public IBeanMapperRule getBeanMapperRule(){
        return new UnderlinedBeanMapperRule();
    }
    
    /**
     * 配置拦截器
     * @author lance
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(createActionInterceptor())
        	.addPathPatterns("/**")//拦截所有请求
        	.excludePathPatterns("/act/test.json")//除了act/test.json请求外
        	.excludePathPatterns("/copy/**")//除了act/test.json请求外
        	.excludePathPatterns("/static/**");
    }

    @Bean
    public MyActionInterceptor createActionInterceptor(){
        return new MyActionInterceptor();
    }
}